package movie.test.login;

import java.util.LinkedHashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import movie.test.as.loginservice.impl.LoginServiceImpl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;

@RestController
@RequestMapping("/loginController")
public class LoginController {

	private static Logger logger = LoggerFactory
			.getLogger(LoginController.class);
	@Autowired
	private LoginServiceImpl loginServiceImpl;
	@RequestMapping("/test")
	public void test(){
    	System.out.println("ddddddd");
    }
	
	/**
	 * 登录
	 * @param objs
	 * @param request
	 * @return
	 * @author lwy
	 * @date 2017-2-28
	 */
	@ResponseBody
	@RequestMapping(value={"/login"},method={RequestMethod.GET,RequestMethod.POST})
	public Object login(@RequestBody JSONObject objs, HttpServletRequest request) {

		try{
			logger.debug("开始登录...");
		    Map map  = loginServiceImpl.loginUser(objs);
			logger.info("登录结束...");
		    Map<String,Object> result = new LinkedHashMap<String,Object>();
			if(map.containsKey("errorcode")){
				result.put("errorcodeInfo", map);
		     
			}else{
		       result.put("successInfo",map);
			}
			return result;
			}
		catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	@ResponseBody
	@RequestMapping(value={"/loginUser"},method={RequestMethod.GET,RequestMethod.POST})
	public Object loginUser(@RequestBody JSONObject objs, HttpServletRequest request) {

		try{
			logger.debug("开始登录...");
		    Map map  = loginServiceImpl.loginUserInfo(objs);
			logger.info("登录结束...");
		    Map<String,Object> result = new LinkedHashMap<String,Object>();
			if(map.containsKey("errorcode")){
				result.put("errorcodeInfo", map);
		     
			}else{
		       result.put("successInfo",map);
			}
			return result;
			}
		catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * @deprecated退出登录
	 * @param reqeust
	 * @return
	 * @date 2017-03-01
	 * 
	 */
	public Object loginOut(HttpServletRequest reqeust){
		try{
			logger.debug("开始退出登录...");
			  loginServiceImpl.loginOut();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return null;
		
	}
}
